<?php
class ProductColoIp extends TbAbstract
{
    protected $_table = 'ProductColoIp';
    static protected  $_instance = null;
	public function getByProduct($id)
	{
		$db = Db::getInstance();
		$query = sprintf("SELECT * FROM ProductColoIp WHERE productId='%s'", $db->real_escape_string($id));
		$result = $db->query($query);
		if(!$result){
			throw new Exception($db->error);
		}
		$buff = array();
		while($row = $result->fetch_assoc()){
			$buff[] = $row;
		}
		return $buff;
	}
	
	public function dump($productId, $ips)
	{
		$db = Db::getInstance();
		$query = "DELETE FROM ProductColoIp WHERE productId='{$productId}'";
		if(!$db->query($query)){
			throw new Exception($db->error);
		}
		foreach($ips as $key => $value){
			$query = sprintf("INSERT INTO ProductColoIp(productId,ip) VALUES('{$productId}','%s')", $db->real_escape_string($value));
			if(!$db->query($query)){
				throw new Exception($db->error);
			}
		}
		return true;
	}
}